package com.aoxin.controller.course.webCourse;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.aoxin.model.SlfVideo;
import com.aoxin.service.inter.course.webCourse.VideoService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.EmptyUtil;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.log.LogInfo;

@RestController
@RequestMapping("/web/video/")
public class VideoController {

    @Autowired
    VideoService videoService;

    /**
     * 新增视频信息
     * @param slfVideo
     * @param res
     * @return
     */
    @RequestMapping("insertVideo")
    @LogInfo(content = "视频信息",operateType = OperateType.INSERT)
    public AjaxRes insertVideo(SlfVideo slfVideo,AjaxRes res){
        try {
            if(!EmptyUtil.objFieldsIsEmpty(slfVideo)){
                Integer result = videoService.insertVideo(slfVideo);
                if(result != 0){
                    res.setSucceedMsg("添加视频成功!");
                }else {
                    res.setFailMsg("添加视频失败!");
                }
            }else {
                res.setFailMsg("视频为空!");
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 查询视频信息
     * @param slfVideo
     * @param res
     * @return
     */
    @RequestMapping("getVideo")
    @LogInfo(content = "视频信息",operateType = OperateType.QUERY)
    public AjaxRes getVideo(SlfVideo slfVideo,AjaxRes res){
        List<SlfVideo> slfVideoPageInfo = videoService.getVideo(slfVideo);
        res.setSucceed(slfVideoPageInfo,"获取视频数据成功!");
        return res;
    }

    /**
     * 修改视频信息
     * @param slfVideo
     * @param res
     * @return
     */
    @RequestMapping("updateVideo")
    @LogInfo(content = "视频信息",operateType = OperateType.UPDATE)
    public AjaxRes updateVideo(SlfVideo slfVideo,AjaxRes res){
        try {
            if(!EmptyUtil.objFieldsIsEmpty(slfVideo)){
                Integer result = videoService.updateVideo(slfVideo);
                if(result != 0){
                    res.setSucceedMsg("更新成功");
                }else {
                    res.setFailMsg("更新失败");
                }
            }else {
                res.setFailMsg("上传视频为空");
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 删除视频信息
     * @param videoId
     * @param res
     * @return
     */
    @RequestMapping("deleteVideo")
    @LogInfo(content = "视频信息",operateType = OperateType.DELETE)
    public AjaxRes deleteVideo(Integer videoId,AjaxRes res){
        if(videoId != null){
            Integer result = videoService.deleteVideo(videoId);
            if(result != 0){
                res.setSucceedMsg("删除视频成功!");
            }else {
                res.setFailMsg("删除视频失败!");
            }
        }else {
            res.setFailMsg("视频为空!");
        }
        return res;
    }

    /**
     * 批量删除视频信息
     * @param videoIds
     * @param res
     * @return
     */
    @RequestMapping("deleteVideos")
    @LogInfo(content = "视频信息",operateType = OperateType.DELETE)
    public AjaxRes deleteVideos(@RequestParam("videoIds") List<Integer> videoIds, AjaxRes res){
        if(videoIds != null && videoIds.size() > 0){
            Integer result = videoService.deleteVideos(videoIds);
            if(result != 0){
                res.setSucceedMsg("批量删除视频成功!");
            }else {
                res.setFailMsg("批量删除视频失败!");
            }
        }else {
            res.setFailMsg("视频为空!");
        }
        return res;
    }


}
